#include <bits/stdc++.h>
using namespace std;

const int N = 100005;
int n, m, L, V, ans1, ans2, d[N], v[N], a[N], p[N];
vector<pair<int, int>> need;

void increase(int d, int v, int a) {
    // 行駛 (V^2-v^2)/2a 後達到臨界
    int w = v > V ? d - 1 : d + (V * V - v * v) / (2 * a);
    // cerr << "w = " << w << endl;
    // 找到第一個 > w 的位置
    int l = upper_bound(p + 1, p + m + 1, w) - p;
    int r = m;
    if (l > r) return;
    ans1++;
    need.emplace_back(l, r);
}

void stable(int d, int v, int a) {
    if (v <= V) return;
    int l = lower_bound(p + 1, p + m + 1, d) - p;
    int r = m;
    if (l > r) return;
    ans1++;
    need.emplace_back(l, r);
}

void decrease(int d, int v, int a) {
    if (v <= V) return;
    int l = lower_bound(p + 1, p + m + 1, d) - p;
    // 行駛 (V^2-v^2)/2*a 後不超速
    int w = d + (v * v - V * V - 2 * a - 1) / (-2 * a);
    // cerr << "w = " << V * V - v * v << "/" << 2 * a << " = " << w - d << endl;
    // 找到最後一個 < w 的位置
    int r = lower_bound(p + 1, p + m + 1, w) - p - 1;
    // cerr << "l, r = " << l << ", " << r << endl;
    if (l > r) return;
    ans1++;
    need.emplace_back(l, r);
}

void solve() {
    ans1 = ans2 = 0;
    need.clear();
    cin >> n >> m >> L >> V;
    for (int i = 1; i <= n; i++)
        cin >> d[i] >> v[i] >> a[i];
    for (int i = 1; i <= m; i++)
        cin >> p[i];
    for (int i = 1; i <= n; i++) {
        // int prv = ans1;
        if (a[i] > 0) increase(d[i], v[i], a[i]);
        if (a[i] == 0) stable(d[i], v[i], a[i]);
        if (a[i] < 0) decrease(d[i], v[i], a[i]);
        // if (ans1 != prv) {
        //     cerr << "detected " << i << endl;
        //     cerr << "can be detected at [" << need.back().first << ", " << need.back().second << "]" << endl;
        // }
    }
    sort(need.begin(), need.end());
    int lst = 0;
    for (auto _ : need) {
        int l, r;
        tie(l, r) = _;
        // cerr << "At least 1 in [" << l << ", " << r << "]" << endl;
        if (l > lst) {
            ans2++;
            lst = r;
        } else {
            lst = min(lst, r);
        }
    }
    cout << ans1 << " " << m - ans2 << endl;
}

int main() {
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int T;
    cin >> T;
    while (T--) solve();
    return 0;
}